package br.com.wayloc.track.libraries;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;

import org.apache.http.client.ClientProtocolException;

import android.util.Log;

public class PostaSMS {
	static InputStream is = null;
	static String resposta;

	// constructor
	public PostaSMS() {
	}

	public String enviaSMS(String url1) {
		// Making HTTP request
		try {
			// defaultHttpClient
			//DefaultHttpClient httpClient = new DefaultHttpClient();
			//HttpGet HttpGet = new HttpGet("http://www.google.com");
			//HttpGet.ssetEntity(new UrlEncodedFormEntity(params));

			//HttpResponse httpResponse = httpClient.execute(HttpGet);
			//HttpEntity httpEntity = httpResponse.getEntity();
			//is = httpEntity.getContent();

			URL url = new URL(url1);
		   HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
		   try {
			   is = new BufferedInputStream(urlConnection.getInputStream());
		   }
		    finally {
		     urlConnection.disconnect();
		    }
			    
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(
				is, "UTF-8"), 8);
			StringBuilder sb = new StringBuilder();
			String line = null;
			while ((line = reader.readLine()) != null) {
				sb.append(line + "\n");
			}
			is.close();
			resposta = sb.toString();
			//Log.e("JSON", json);
		} catch (Exception e) {
			Log.e("Buffer Error", "Error converting result " + e.toString());
		}

		return resposta;
	}
}